﻿@model ExceptionsModel
@{
    var store = Model.Store?.Name;
    var group = Model.Group?.Name;
    var log = Model.Log?.Name;
    var url = Model.SearchParams.Url;
    var host = Model.SearchParams.Host;
    var normalizedStartDate = Model.SearchParams.NormalizedStartDate;
    var normalizedEndDate = Model.SearchParams.NormalizedEndDate;
    var exceptions = Model.Errors;

    this.SetPageTitle(Model.Title);
    this.SetTopSearch((log.HasValue() ? log + " " : "") + "Exceptions",
              Model.Search,
              Url.Action(nameof(ExceptionsController.Exceptions)),
              Model.SearchDictionary);
    var anyLoaded = Module.Stores?.Any(s => s.HasPolledCacheSuccessfully && s.MonitorStatus == MonitorStatus.Good) ?? false;
}
@section head {
    <script>
        $(function () {
            Status.Exceptions.init({
                refresh: 120,
                store:@store.ToJson(),
                group: @group.ToJson(),
                log: @log.ToJson(),
                sort: '@Model.Sort',
                loadMore: @(Model.LoadAsyncSize),
                enablePreviews: @Module.Settings.EnablePreviews.ToJson(),
                showDeleted: @Model.ShowDeleted.ToJson(),
                search: @Model.Search.ToJson(),
                url: @url.ToJson(),
                host: @host.ToJson(),
                startDate: @normalizedStartDate.ToJson(),
                endDate: @normalizedEndDate.ToJson()
            });
        });
    </script>
}
<div class="js-refresh" data-name="exceptions-header">
    @if (Module.Stores.Count > 1)
    {
        <ul class="nav nav-tabs nav-tabs-right">
            @foreach (var s in Module.Stores)
            {
                <li class="@(Model.Store == s ? "active" : null)">
                    <a href="?store=@s.Name" title="@s.Description">@s.Name <span class="badge"><span class="js-exception-total js-exception-store" data-name="@s.Name">@s.TotalExceptionCount.ToComma()</span></span></a>
                </li>
            }
        </ul>
    }
    <partial name="PollInfo" model="@(new Opserver.Views.PollInfoModel { Nodes = Module.Stores, Name = "exceptions" })" />
    @if (anyLoaded)
    {
        <div class="js-exception-counts">
            <partial name="Exceptions.Navigation" model="Model" />
        </div>
    }
</div>
@if (anyLoaded)
{
    <div class="js-refresh" data-name="exceptions-list">
        <partial name="Exceptions.Table" model="Model" />
        <div class="js-bottom-loader horizontal-load"><div class="sk-wave"><div></div><div></div><div></div><div></div><div></div></div></div>
        <div class="js-bottom-no-exceptions no-content text-success@(exceptions.Any() ? " hidden" : "")">No @log exceptions</div>
        <div class="js-bottom-no-more no-content small@(Model.HasMore ? null : " hidden")">End of active exception log</div>
    </div>
}